<?php
include("check.php");
/*include("check2.php");*/
include_once("../function.php");
header("Content-Type: text/html;charset=utf-8");
session_start();
$us=que_select_cl('member',$_SESSION['ID']);
$ul=ulevel($us['ulevel']);
$j=$ul['yl20'];
$e=$ul['yl19'];
$sql="select fuwuzhongxi from systemparameters where id=1";
$rs=getOne($sql);
if ($_POST['submit']){
    $uid=$_SESSION['ID'];
    if($_POST['bdlevel']==1){
        //	if($us['ulevel']==3){
        //if($us['area1']>=90000 && $us['area2']>=90000){
        //if(sqfwzx($us['id'])){
        if($us['isbd']==0){
            $sql="update member set isbd=1 where id={$uid}";
            mysql_query($sql);
            alert("申请提交成功，请等待审核通过。");
        }else{
            alert("您已申请为服务中心，请不要重复申请","?");
        }
        //}else{
        //alert("您没有推荐两个或两个以上相同级别的会员，申请失败！","?");
        //}
        //}else{
        //alert("您的小区业绩没有达到90000，申请失败！","?");
        //}
        /*	}else {
                alert("您当前的级别没有达到钻卡，请先申请升级！","?");
            }*/

    }elseif($_POST['bdlevel']==2){
        if($_POST['jine']>=1800){
            if($_POST['county']>0){
                if($us['bdlevel']==0){
                    $sa="select id from member where bddiqu={$_POST['county']}";
                    $ss=getOne($sa);
                    if(empty($ss)){
                        $sql="update member set isbd=1,bddiqu={$_POST['county']},bdlevel=1,sqbdje={$_POST['jine']} where id={$uid}";
                        mysql_query($sql);
                        alert("申请提交成功，请等待审核通过。");
                    }else{
                        alert("该地区已有代理","?");
                    }
                }else{
                    alert("您已经是县区店","?");
                }
            }else{
                alert("请选择代理的县区","?");
            }
        }else{
            alert("申请金额不能小于1800","?");
        }
    }
// 	elseif($_POST['bdlevel']==3){
// 	    if($_POST['jine']>=$e){
// 	        if($_POST['city']>0){
// 	            if($us['bdlevel']<2){
// 	                $sa="select id from member where bddiqu={$_POST['city']}";
// 	                $ss=getOne($sa);
// 	                if(empty($ss)){
// 	                    $sql="update member set isbd=1,bddiqu={$_POST['city']},bdlevel=2,sqbdje={$_POST['jine']} where id={$uid}";
// 	                    mysql_query($sql);
// 	                    alert("申请提交成功，请等待审核通过。");
// 	                }else{
// 	                    alert("该地区已有代理","?");
// 	                }
// 	            }else{
// 	            	alert("您已经是市级店","?");
// 	            }

// 	        }else{
// 	            alert("请选择代理的县区","?");
// 	        }
// 	    }else{
// 	        alert("请输入正确的金额","?");
// 	    }
// 	}else{
// 		alert("请选择级别","?");
// 	}
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="css/table.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <title>服务中心申请</title>
    <script src='../js/shengshixian/jquery-1[1].2.6.js'></script>
    <script src="../js/shengshixian/jquery.provincesCity.js" type="text/javascript"></script>
    <script src="../js/shengshixian/provincesdata.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="./css/iconfont.css"/>
    <link href="css/style1.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="./he/jquery.ui.autocomplete.css">
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <script src="./js/style.js" type="text/javascript" charset="utf-8"></script>
    <script>
        //调用插件
        $(function(){
            $("#test").ProvinceCity();
            $("#a1").click(function(){
                $("#diqu").hide();
                $("#jine").val("<?php echo $j;?>");
                $("#jinebar").hide();

            });
            $("#a2").click(function(){
                $("#diqu").show();
                $("#jine").val("<?php echo $j;?>");
                $("#jinebar").show();
                $("#county").show();
            });
            $("#a3").click(function(){
                $("#diqu").show();
                $("#jine").val("<?php echo $e;?>");
                $("#jinebar").show();
                $("#county").hide();
            });
            $("#province").change(function(){
                $.ajax({
                    type:"get",
                    url:"diqu.php?province="+this.value,
                    dataType:"text",
                    success:function(a){
                        $("#city").html(a);
                    }

                })
            })

            $("#city").change(function(){
                $.ajax({
                    type:"get",
                    url:"diqu.php?city="+this.value,
                    dataType:"text",
                    success:function(a){
                        $("#county").html(a);
                    }

                })
            })

        });
        function check(){
            var county=document.form1.county.value;
            var city=document.form1.city.value;
            var ra=document.getElementsByName('bdlevel');
            for(var i=0;i<ra.length;i++){
                if(ra[i].checked ==true){
                    var rav=ra[i].value;
                }
            }
            if(rav==2){
                if(county<0){
                    alert("请选择县");
                    return false;
                }
            }else if(rav==3){
                if(city<0){
                    alert("请选择市");
                    return false;
                }
            }

            return true;

        }
    </script>
    <style>
        #test select{
            width:100px;
        }
        .yincang{
            display:none;
        }
        xianshi{
            display:block;
        }
    </style>
</head>
<body>
<?php
$title="申请服务中心";
include_once("./public/header_nav.html");
?>
<form name="form1" method="post" action="?" onsubmit="return check();">
    <?php
    $_member=que_select_cl('member',$_SESSION['ID']);
    if ($_member['isbd']==0){
    ?>
    <table  width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
        <tr>
            <td width="50%" height="22" align="right">申请会员编号：</td>
            <td width="65%" align="left"><input name="nickname" type="text" id="nickname" size="20" maxlength="20" value="<?=$_SESSION['nickname']?>" readonly></td>
        </tr>
        <tr style="display:none">
            <td width="35%" height="22" align="right">服务中心名称：</td>
            <td width="65%" align="left"><input name="bdnickname" type="text" id="bdnickname" size="20" maxlength="20" value=""></td>
        </tr>
        <tr >
            <td width="35%" height="22" align="right">服务中心级别：</td>
            <td width="65%" align="left">
                <!-- <select name="bdlevel" id="bdlevel">
                       <option value="1">A级</option>
                       <option value="2">B级</option>
                     </select> -->
                <input type="radio" id="a1" name="bdlevel" value="1" checked="checked"/><label for="a1">服务中心</label>
                <!-- <input type="radio" id="a2" name="bdlevel" value="2"/><label for="a2">县级代理</label> -->
            </td>
        </tr>
<!--        <tr id="diqu" --><?php //if(empty($us['bdlevel'])){ ?><!--class="yincang"--><?php //}?><!-->
<!--            <td height="22" align="right">负责地区：</td>-->
<!--            <td align="left">-->
<!--                <!-- <div id="test"></div> -->
<!--                <select id="province" name="province">-->
<!--                    <option value="-1">请选择省份</option>-->
<!--                    --><?php
//                    $sql="select * from province";
//                    $rs=getAll($sql);
//                    foreach($rs as $v){
//                        ?>
<!--                        <option value="--><?php //echo $v['provinceid']?><!--">--><?php //echo $v['province']?><!--</option>-->
<!--                    --><?php //}?>
<!--                </select>-->
<!--                <select name="city" id="city">-->
<!--                    <option value="-1">请选择城市</option>-->
<!--                </select>-->
<!--                <select name="county" id="county">-->
<!--                    <option value="-1">请选择县区</option>-->
<!--                </select>-->
<!--            </td>-->
<!--        </tr>-->
        <tr id="jinebar" style="display:none">
            <td height="22" align="right">申请金额：</td>
            <td align="left"><input name="jine" type="text" id="jine" value="1800" size="20" maxlength="20"></td>
        </tr>
        <tr style="display:none">
            <td height="22" align="right">备注：</td>
            <td align="left">
                <textarea name="bdbeizhu" id="bdbeizhu" cols="45" rows="5"></textarea></td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input name="submit" id="submit" type="submit" class="button_green" value="申  请"></td>
        </tr>
    </table>
    <table>
        <tr><td height="22" style="font-size: 1.6rem">
                <?php
                }else if($_member['isbd']==1){
                    echo "您的申请已经提交,正在审核中,请耐心等待.";
                }else if($_member['isbd']==2){
                    $name="服务中心";
                    echo "您申请的{$name}已通过管理员审核,您的服务中心编号为：".$_SESSION['nickname']."。 ".$diqu;
                }elseif ($_member['isbd']==3){
                    switch($_member['bdlevel']){
                        case 1:$name="县区店";break;
                        case 2:$name="市级店";break;
                    }
                    echo $diqu="您代理的地区为:".lol($_member['bddiqu'],$_member['bdlevel']);
                }
                ?>
            </td>
        </tr>
    </table>
</form>

<?php include_once ("public/footer_nav.html")?>
</body>
</html>